package com.landian.commons.jpa.criteria;

import com.landian.commons.jpa.utils.PathUtils;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.Date;

/**
 *
 * @author caojl
 * @create 2017/11/29
 **/
class GePredicable implements Predicable {

    private com.querydsl.core.types.Path dslPath;

    private Date value;

    private GePredicable(com.querydsl.core.types.Path<?> dslPath, Date value) {
        this.dslPath = dslPath;
        this.value = value;
    }

    public static GePredicable newInstance(com.querydsl.core.types.Path<?> dslPath, Date value) {
        return new GePredicable(dslPath, value);
    }

    @Override
    public Predicate build(Root<?> root, CriteriaBuilder cb) {
        String fieldName = PathUtils.getFieldName(dslPath);
        Path path = root.get(fieldName);
        Predicate predicate = cb.greaterThanOrEqualTo(path, value);
        return predicate;
    }
}